import pymysql
class Dept():
    def __init__(self,no,name,location):
        self.no = no
        self.name = name
        self.location =location
    def __str__(self):
        return f'{self.no}\t{self.name}\t{self.location}'

def main():
    # no = int(input("请输入你要查询的部门编号："))
    conn = pymysql.connect(host='',port=3306,
                           user='root',password='admin@9000',
                           database='my_database',charset='utf8',
                           cursorclass=pymysql.cursors.DictCursor)
    try:
        with conn.cursor() as cursor:
            cursor.execute("select deptno as no,dname as name ,location  from tb_dept  ")

            # print(cursor.fetchall())
            for row in cursor.fetchall():
                # print(row)
                # print(row['no'],end="\t")
                # print(row['name'],end="\t")
                # print(row['location'])
                dept = Dept(**row)
                print(dept)

                # print('-'*20)
    except pymysql.MySQLError as error:
        print(error)
    finally:
        conn.close()

    print(conn)

if __name__ == '__main__':
    main()